<?php

class Model_App_Project extends PhalApi_Model_NotORM {
    /**
     * 根据PID 查询项目 数据
     */
    public function getProjectByPid($pid){
        return DI()->notorm
            ->project
            ->where('pid = ?', $pid)
            ->fetchOne();
    }

    /**
     * 添加 一条项目
     */

    public function add($data) {
        return DI()->notorm
            ->project
            ->insert($data);
    }

    /**
     * 检查是否重复提交
     */

    public function checkProjectDup($data){
        return DI()->notorm
            ->project
            ->where('pid = ?', $data['pid'])
            ->fetchOne();
    }
    /**
     * 根据 admin (openid) 来查询  客户的项目
     */
    public function plists($data){
        return DI()->notorm
            ->project
            ->where('admin = ?', $data['admin'])
            ->fetchAll();
    }

    /**
     * 根据 pid 删除对应的项目资料
     */

    public function delete($data) {
        return DI()->notorm
            ->project
            ->where('pid = ?', $data['pid'])
            ->delete();
    }


    public function edit($data,$pid) {
        return DI()->notorm
            ->project
            ->where('pid = ?', $pid)
            ->update($data);
    }

    protected function getTableName($id) {
        return 'projects';
    }
}
